<template>
    <div class="mt-4">
        <n-drawer v-model:show="rlsdrawer" :width="1200">
            <n-drawer-content :title="title" closable>
            <n-card :bordered="false" class="mt-4 proCard">
            <BasicTable
                :columns="columns"
                :request="loadDataTable"
                :row-key="(row:ListData) => row.userId"
                ref="actionRef"
                @update:checked-row-keys="onCheckedRow"
            >
                <template #tableTitle>
                  <n-button type="primary" :disabled="isRowKeysEmpty1" @click="deleteEmp">
                      删除
                  </n-button>
                </template>
                <template #toolbar>
                <n-button type="primary" @click="reloadTable1">刷新数据</n-button>
                </template>
            </BasicTable>
            </n-card>
            </n-drawer-content>
        </n-drawer>
    </div>
  </template>
  <script lang="ts" setup>
  import { ref,defineProps,computed } from 'vue';
  import { BasicTable } from '@/components/Table';
  import { columns, ListData } from '@/views/equipment/components/rlsemplistcolumns';
  import { getRlsedEmpList,deleteEmpEquip } from '@/api/equipment/equipment_list';
  
  const actionRef = ref();
  const rlsdrawer = ref();
  const title = ref();
  const props = defineProps(['parentData','show']);

  const rowKeys = ref([]);

  function onCheckedRow(rKeys) {
    rowKeys.value = rKeys;
  }

  const isRowKeysEmpty1 = computed(() => {
    return rowKeys.value.length === 0;
  });


  rlsdrawer.value = props.show;
  title.value = "已下发人员信息 （设备：" + props.parentData.split(',')[1] + "）"
  // 加载数据表
  const loadDataTable = async (res) => {
    const data = await getRlsedEmpList({ equipid: props.parentData.split(',')[0],...res });
    return data;
  };
  
  async function deleteEmp() {
    await deleteEmpEquip({equipid: props.parentData.split(',')[0],empList: rowKeys.value}).then(() => {
      reloadTable1();
    });
  }

  function reloadTable1() {
    actionRef.value.reload();
  }



  </script>
  